# © 2021 and later: Unicode, Inc. and others.
# License & terms of use: http://www.unicode.org/copyright.html

# This file defines Bazel targets for a subset of ICU4C "common" library header and source files.
# The configuration of dependencies among targets is strongly assisted by the
# file in depstest that maintains such information, at
# icu4c/source/test/depstest/dependencies.txt .

load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")

package(
    default_visibility = ["//visibility:public"],
)

# When compiling code in the `common` dir, the constant
# `U_COMMON_IMPLEMENTATION` needs to be defined. See 
# https://unicode-org.github.io/icu/userguide/howtouseicu#c-with-your-own-build-system .

# If linker errors occur, then this may be a sign that the dependencies were 
# not specified correctly. Use dependencies.txt in depstest for assistance. See
# https://stackoverflow.com/q/66111709/2077918 .

cc_library(
    name = "headers",
    hdrs = glob([
        "unicode/*.h", # public
        "*.h",         # internal
        ],
        # Instead of using these checked-in files, our Bazel build process
        # regenerates them and then uses the new versions.
        # Same list of .h files as in icu4c/source/data/unidata/clean.sh.
        exclude = ["norm2_nfc_data.h", "propname_data.h", "*_props_data.h"],
    ),
    # We need to add includes in order to preserve existing source files'
    # include directives that use traditional paths, not paths relative to
    # Bazel workspace:
    # https://stackoverflow.com/a/65635893/2077918
    includes = ["."],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "platform",
    srcs = [
        "cmemory.cpp", 
        "uobject.cpp",
        "cstring.cpp",
        "cwchar.cpp",
        "uinvchar.cpp",
        "charstr.cpp",
        "unistr.cpp",
        "appendable.cpp",
        "stringpiece.cpp",
        "ustrtrns.cpp",
        "ustring.cpp",  
        "ustrfmt.cpp",  
        "utf_impl.cpp",
        "putil.cpp",
        "ucln_cmn.cpp",  
        "udataswp.cpp",  
        "umath.cpp",
        "umutex.cpp",
        "sharedobject.cpp",
        "utrace.cpp",
    ],
    deps = [
        ":headers",
        # omit other deps b/c they are sys symbols
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
    linkopts = ["-ldl"],
)

cc_library(
    name = "utrie",
    srcs = ["utrie.cpp"],
    deps = [":platform"],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "utrie2",
    srcs = ["utrie2.cpp"],
    deps = [":platform"],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "utrie2_builder",
    srcs = ["utrie2_builder.cpp"],
    deps = [
        ":utrie",
        ":utrie2",
        ":platform",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "ucptrie",
    srcs = ["ucptrie.cpp"],
    deps = [":platform"],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "umutablecptrie",
    srcs = ["umutablecptrie.cpp"],
    deps = [":ucptrie"],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "bytestrie",
    srcs = ["bytestrie.cpp"],
    deps = [":platform"],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "bytestriebuilder",
    srcs = ["bytestriebuilder.cpp"],
    deps = [
        ":bytestrie",
        ":stringtriebuilder",
        ":sort",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "stringtriebuilder",
    srcs = ["stringtriebuilder.cpp"],
    deps = [
        ":uhash",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "uhash",
    hdrs = [
        "uhash.h",
    ],
    srcs = [
        "uhash.cpp",
    ],
    deps = [
        ":headers",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "errorcode",
    hdrs = [
    ],
    srcs = [
        "errorcode.cpp",
    ],
    includes = ["."],
    deps = [
        ":platform",
        ":utypes",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "utypes",
    srcs = [
        "utypes.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "uniset",
    srcs = [
        "uniset.cpp",
        "unifilt.cpp",
        "unisetspan.cpp",
        "bmpset.cpp",
        "util.cpp",
        "unifunct.cpp",
        "usetiter.cpp",
    ],
    includes = ["."],
    deps = [
        ":patternprops",
        ":uvector",
        ":headers",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "patternprops",
    srcs = [
        "patternprops.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "propsvec",
    srcs = [
        "propsvec.cpp",
    ],
    includes = ["."],
    deps = [
        ":sort",
        ":utrie2_builder",
        ":headers",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "propname",
    srcs = [
        "propname.cpp",
        "propname_data.h",
    ],
    includes = ["."],
    deps = [
        ":bytestrie",
        ":headers",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

# Note: The cc_library target names "uvector32" and "uvector64" match the
# dependencies.txt group names, but the filenames are "uvectr32.*"/"uvectr64.*".
cc_library(
    name = "uvector32",
    srcs = [
        "uvectr32.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":platform",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "uvector64",
    srcs = [
        "uvectr64.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":platform",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "sort",
    srcs = [
        "uarrsort.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "uvector",
    srcs = [
        "uvector.cpp",
    ],
    includes = ["."],
    deps = [
        ":platform",
        ":sort",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "breakiterator",
    srcs = [
        "brkiter.cpp",
        "brkeng.cpp",
        "dictbe.cpp",
        "dictionarydata.cpp",
        "filteredbrk.cpp",
        "lstmbe.cpp",
        "mlbe.cpp",
        "rbbi.cpp",
        "rbbi_cache.cpp",
        "rbbidata.cpp",
        "rbbinode.cpp",
        "rbbirb.cpp",
        "rbbiscan.cpp",
        "rbbisetb.cpp",
        "rbbistbl.cpp",
        "rbbitblb.cpp",
        "ubrk.cpp",
    ],
    includes = ["."],
    deps = [
        ":bytestrie",
        ":headers",
        ":normlzr",
        ":resourcebundle",
        ":schriter",
        ":service_registration",
        ":ucharstrie",
        ":ucharstriebuilder",
        ":uhash",
        ":uniset_core",
        ":uniset_props",
        ":ustack",
        ":utext",
        ":utrie2_builder",
        ":uvector32",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "bytesinkutil",
    srcs = [
        "bytesinkutil.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":bytestream",
        ":edits",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "bytestream",
    srcs = [
        "bytestream.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":platform",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "canonical_iterator",
    srcs = [
        "caniter.cpp",
    ],
    deps = [
        ":normalizer2",
        ":usetiter",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "characterproperties",
    srcs = [
        "characterproperties.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":emojiprops",
        ":ucptrie",
        ":umutablecptrie",
        ":uniset_core",
        ":uprops",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "chariter",
    srcs = [
        "chariter.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":platform",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "edits",
    srcs = [
        "edits.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":icu_utility",
        ":platform",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "filterednormalizer2",
    srcs = [
        "filterednormalizer2.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":normalizer2",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "hashtable",
    srcs = [
        "uhash_us.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":uhash",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "icu_utility",
    srcs = [
        "util.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":patternprops",
        ":platform",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "loadednormalizer2",
    srcs = [
        "loadednormalizer2impl.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":normalizer2",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "locale_display_names",
    srcs = [
        "locdispnames.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":locresdata",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "locresdata",
    srcs = [
        "locresdata.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":resourcebundle",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "normlzr",
    srcs = [
        "normlzr.cpp",
    ],
    includes = ["."],
    deps = [
        ":filterednormalizer2",
        ":headers",
        ":schriter",
        ":uniset_props",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "parsepos",
    srcs = [
        "parsepos.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":platform",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "resourcebundle",
    srcs = [
        "localebuilder.cpp",
        "locavailable.cpp",
        "locbased.cpp",
        "locid.cpp",
        "loclikely.cpp",
        "loclikelysubtags.cpp",
        "locmap.cpp",
        "lsr.cpp",
        "resbund.cpp",
        "resource.cpp",
        "uloc.cpp",
        "uloc_tag.cpp",
        "uloc_keytype.cpp",
        "ulocale.cpp",
        "ulocbuilder.cpp",
        "uresbund.cpp",
        "uresdata.cpp",
        "wintz.cpp",
    ],
    includes = ["."],
    deps = [
        ":bytesinkutil",
        ":errorcode",
        ":headers",
        ":propname",
        ":sort",
        ":stringenumeration",
        ":ucol_swp",
        ":udata",
        ":uhash",
        ":uscript_props",
        ":uvector",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "schriter",
    srcs = [
        "schriter.cpp",
        "uchriter.cpp",
    ],
    includes = ["."],
    deps = [
        ":chariter",
        ":headers",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "service_registration",
    srcs = [
        "locutil.cpp",
        "serv.cpp",
        "servlk.cpp",
        "servlkf.cpp",
        "servls.cpp",
        "servnotf.cpp",
        "servrbf.cpp",
        "servslkf.cpp",
    ],
    includes = ["."],
    deps = [
        ":hashtable",
        ":headers",
        ":locale_display_names",
        ":resourcebundle",
        ":uvector",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "stringenumeration",
    srcs = [
        "uenum.cpp",
        "ustrenum.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":platform",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "ubidi_props",
    srcs = [
        "ubidi_props.cpp",
        "ubidi_props_data.h",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":utrie2",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "ucase",
    srcs = [
        "ucase.cpp",
        "ucase_props_data.h",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":utrie2",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "uchar",
    srcs = [
        "uchar.cpp",
        "uchar_props_data.h",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":utrie2",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "emojiprops",
    srcs = [
        "emojiprops.cpp",
        "emojiprops.h",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":ucharstrie",
        ":ucharstrieiterator",
        ":ucptrie",
        ":udata",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "ucharstrie",
    srcs = [
        "ucharstrie.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":platform",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "ucharstriebuilder",
    srcs = [
        "ucharstriebuilder.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":sort",
        ":stringtriebuilder",
        ":ucharstrie",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "ucharstrieiterator",
    srcs = [
        "ucharstrieiterator.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":ucharstrie",
        ":uvector32",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "ucol_swp",
    srcs = [
        "ucol_swp.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":utrie_swap",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "udata",
    srcs = [
        "restrace.cpp",
        "ucmndata.cpp",
        "udata.cpp",
        "udatamem.cpp",
        "umapfile.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":icu_utility",
        ":platform",
        ":uhash",
        "//icu4c/source/stubdata",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "uiter",
    srcs = [
        "uiter.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":platform",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "ulist",
    srcs = [
        "ulist.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":platform",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "unames",
    srcs = [
        "unames.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":uchar",
        ":udata",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "unifiedcache",
    srcs = [
        "unifiedcache.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":platform",
        ":uhash",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "uniset_core",
    srcs = [
        "bmpset.cpp",
        "unifilt.cpp",
        "unifunct.cpp",
        "uniset.cpp",
        "unisetspan.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":icu_utility",
        ":patternprops",
        ":uvector",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "uniset_closure",
    srcs = [
        "uniset_closure.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":uniset_core",
        ":unistr_case_locale",
        ":unistr_titlecase_brkiter",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "uniset_props",
    srcs = [
        "uniset_props.cpp",
        "ruleiter.cpp",
    ],
    includes = ["."],
    deps = [
        ":characterproperties",
        ":headers",
        ":parsepos",
        ":propname",
        ":resourcebundle",
        ":unames",
        ":uniset_core",
        ":unistr_case",
        ":uprops",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "unistr_case",
    srcs = [
        "unistr_case.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":ustring_case",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "unistr_case_locale",
    srcs = [
        "unistr_case_locale.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":unistr_case",
        ":ustring_case_locale",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "unistr_titlecase_brkiter",
    srcs = [
        "unistr_titlecase_brkiter.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":ustr_titlecase_brkiter",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "uprops",
    srcs = [
        "uprops.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":emojiprops",
        ":loadednormalizer2",
        ":normalizer2",
        ":ubidi_props",
        ":ucase",
        ":uchar",
        ":unistr_case",
        ":ustring_case",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "uscript_props",
    srcs = [
        "uscript_props.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":platform",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "uset",
    srcs = [
        "uset.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":platform",
        ":uniset_core",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "uset_props",
    srcs = [
        "uset_props.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":uniset_closure",
        ":uniset_core",
        ":uniset_props",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "usetiter",
    srcs = [
        "usetiter.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":platform",
        ":uniset_core",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "ustack",
    srcs = [
        "ustack.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":uvector",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "ustr_titlecase_brkiter",
    srcs = [
        "ustr_titlecase_brkiter.cpp",
    ],
    includes = ["."],
    deps = [
        ":breakiterator",
        ":headers",
        ":ucase",
        ":ustring_case_locale",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "ustring_case",
    srcs = [
        "ustrcase.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":ucase",
        ":uchar",
        ":edits",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "ustring_case_locale",
    srcs = [
        "ustrcase_locale.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":resourcebundle",
        ":ustring_case",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "utext",
    srcs = [
        "utext.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":ucase",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

cc_library(
    name = "utrie_swap",
    srcs = [
        "utrie_swap.cpp",
    ],
    includes = ["."],
    deps = [
        ":headers",
        ":udata",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)

# This target depends on a header file that contains NFC/NFD normalization data.
# This header file is generated by a script (generate.sh) that invokes the gennorm2 binary.
# See the Unicode update change log (changes.txt).
cc_library(
    name = "normalizer2",
    srcs = [
        "norm2_nfc_data.h",  # generated by gennorm2
        "normalizer2.cpp",
        "normalizer2impl.cpp",
    ],
    includes = ["."],
    hdrs = [
        "normalizer2impl.h",
    ],
    deps = [
        ":headers",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",  
    ],
)
